package com.yxj.controller;


import com.alibaba.fastjson.JSON;
import com.yxj.domain.PmsCategory;
import com.yxj.service.IPmsCategoryService;
import com.yxj.vo.PmsCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 商品三级分类 前端控制器
 * </p>
 *
 * @author yxj
 * @since 2023-03-18
 */
@RestController
public class PmsCategoryController {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Resource
    private IPmsCategoryService pmsCategoryService;

    @GetMapping("/pms-category")
    public List<PmsCategory> getList() {

        if (redisTemplate.hasKey("pmsCategories")) {

            String pmsCategories = redisTemplate.opsForValue().get("pmsCategories");
            return JSON.parseObject(pmsCategories,List.class);
        }
        List<PmsCategory> list = pmsCategoryService.find();
        redisTemplate.opsForValue().set("pmsCategories",JSON.toJSONString(list));
        return list;

    }

}
